package cn.calm.swing.osgi.generator;

import java.util.Hashtable;

import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;

import cn.calm.swing.osgi.api.SwingOsgiBundleActivator;
import cn.calm.swing.osgi.api.WizardItemService;
import cn.calm.swing.osgi.generator.service.GeneratorProjectService;
import cn.calm.swing.osgi.generator.service.GeneratorWizardItemService;
import cn.calm.swing.osgi.generator.ui.Generator;

public class Activator extends SwingOsgiBundleActivator {
	private ServiceRegistration<WizardItemService> registerService;
	private ServiceRegistration<Generator> registerGenerator;
	private Generator generator;

	@Override
	public void start(BundleContext context) throws Exception {
		Hashtable<String, String> para = new Hashtable<String, String>();
		para.put(WizardItemService.WIZARD_ITEM_TREE, "Generator");
		registerService = context.registerService(WizardItemService.class,
				new GeneratorWizardItemService(context), para);
		generator = new Generator(context);
		registerGenerator = context.registerService(Generator.class, generator,
				null);
		loadProject(context,Generator.PROJECT_TYPE,GeneratorProjectService.class);
	}

	@Override
	public void stop(BundleContext context) throws Exception {
		if (registerService != null) {
			registerService.unregister();
		}
		if (registerGenerator != null) {
			registerGenerator.unregister();
		}
	}
}
